#ifndef __LIB_AGORA_ADMIN_INTERPRETER_H__
#define __LIB_AGORA_ADMIN_INTERPRETER_H__

#include <map>
#include <stack>
#include "AdminIChannelManager.h"
#include "AdminIUserManager.h"
#include "Header.h"

//#include "AdminIRightManager.h"

using namespace AgoraCore;

namespace AgoraAdmin
{

	class AdminInterpreter
	{
	public:
		struct ReturnInfo
		{
			AdminFunction		_function;
			void				*_informations;
			unsigned int		_size;
			std::list<IUser *>	_userConcerned;
		};

		typedef void (*Callback)(IUser *user, void *data);
		
		void								SubscribeForcedDisconnectionUser(Callback fct, void *data);
		ReturnInfo*							ConnectUser(IUser* user);
		ReturnInfo*							DisconnectUser(IUser* user);

		AdminInterpreter(IChannelManager *ch, /* IRightManager *rt,*/ IUserManager *us); 
		std::stack<ReturnInfo*>								Launch(IUser* user, AdminFunction function, void *argument);
	private:
		void												SetError(unsigned int code, const std::string& message, ReturnInfo* res);
		std::stack<ReturnInfo*>								GetAllChannel(IUser* user, void *data);
		std::stack<ReturnInfo*>								CreateChannel(IUser* user, void* data);
		std::stack<ReturnInfo*>								JoinChannel(IUser* user, void* data);
		std::stack<ReturnInfo*>								GetAllUser(IUser* user, void* data);
		std::stack<ReturnInfo*>								GetHostRight(IUser* user, void* data);
		std::stack<ReturnInfo*>								GetChannelRight(IUser* user, void* data);
		std::stack<ReturnInfo*>								DeleteChannel(IUser* user, void* data);
		std::stack<ReturnInfo*>								CreateUser(IUser* user, void* data);
		std::stack<ReturnInfo*>								DeleteUser(IUser* user, void* data);
		std::stack<ReturnInfo*>								KickUser(IUser* user, void* data);
		std::stack<ReturnInfo*>								BanUser(IUser* user, void* data);
		std::stack<ReturnInfo*>								GetBanUserList(IUser* user, void* data);
		std::stack<ReturnInfo*>								UnBanUser(IUser* user, void* data);
		std::stack<ReturnInfo*>								EditUserChannelRight(IUser* user, void* data);
		std::stack<ReturnInfo*>								EditUserHostRight(IUser* user, void* data);
		std::stack<ReturnInfo*>								ChangeUserLogin(IUser* user, void* data);
		std::stack<ReturnInfo*>								ChangeUserPassword(IUser* user, void* data);
		std::stack<ReturnInfo*>								GetUserChannelRight(IUser* user, void* data);
		std::stack<ReturnInfo*>								GetUserHostRight(IUser* user, void* data);
		std::stack<ReturnInfo*>								EditChannel(IUser* user, void* data);
		std::stack<ReturnInfo*>								SendMessage(IUser* user, void* data);
		std::stack<ReturnInfo*>								KickUserServer(IUser* user, void* data);
		/*std::stack<ReturnInfo*>								MuteUser(IUser* user, void* data);
		std::stack<ReturnInfo*>								GetMuteUserList(IUser* user, void* data);
		std::stack<ReturnInfo*>								UnMuteUser(IUser* user, void* data);*/
		std::stack<ReturnInfo*>								BanUserServer(IUser* user, void* data);
		std::stack<ReturnInfo*>								UnBanUserServer(IUser* user, void* data);
		std::stack<ReturnInfo*>								GetBanUserListServer(IUser* user, void* data);
		std::stack<AgoraAdmin::AdminInterpreter::ReturnInfo*> CreateStackFromOneRes(ReturnInfo* res);
		void								FillUserConcerned(ReturnInfo* res);

		

	
		Callback							_callback;
		bool								_callbackOk;
		void*								_callbackData;


		IChannelManager*					_channelManager;
		//	IRightManager *_rightManager;
		IUserManager*						_userManager;
		typedef std::stack<ReturnInfo*>		(AdminInterpreter::*function)(IUser* user, void*);
		std::map<AdminFunction, function>	_adminFunctions;
	};

}

#endif
